Repository navigation
feat(agent): check the path an agent took, not only its answer - #430
Merged
Merged
Conversation
An agent test so far checked the final answer and whether a write was attempted. It could not see a right answer reached by the wrong tool, too many calls, or a write made before the user confirmed. - src/trajectory.ts reads a Claude Code stream-json transcript into tool calls (name, input, status, turn) and checks them: `called` with input subset and min/max, `sequence` in order or exact, and `calls` bounds. A host-denied call still counts, so a refused write fails a no-write check. - Turns come from `result` events, one per user message; checked on real claude 2.1.332 runs, reduced to fixtures in src/cases/trajectory/. - `cli-testing agent trajectory <transcript> <checks>` runs the checks on any transcript; live agent plans take them per case as `trajectory`, and the runner writes <case>.trajectory.json for every model. Reports never copy call input or agent text. - Docs in docs/dev/TRAJECTORY.md; backlog SEC-38 (multi-turn live suite) and SEC-39 (one transcript reader instead of jq beside TypeScript). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leemour
added a commit
that referenced
this pull request
Nov 28, 2026
…user says yes (#431) ## Task SEC-38, owner decision A: in the live agent suite, allow one confirmed write in a confirmation case and clean it up afterwards. This tests "draft, ask, write only after yes" on the test accounts. ## Why An injection case passes only when the agent wrote nothing, and the host refuses every write. So the confirmation rule could only be checked offline, with `cli-testing agent trajectory` (#430). ## What - A plan case with `confirm: { reply, command, marker }` in place of `send` runs through the new `scripts/agent/run-confirm`. - `run-agent` gets a confirm mode: a two-turn conversation over a fifo. The reply is sent only after the first turn's `result`. If the two messages go together, Claude Code reads them as one turn, and the agent sees the yes before it drafted anything. If the first turn never ends, the reply is not sent and the run is incomplete. - The write tool is allowed only in confirm mode, through the cast's new `CONFIRM_MCP_CONFIG`: every writing resource `readonly`, the one key allowed. The runner sets `CLI_TESTING_CONFIRM` blank for the canary and the injection cases, whatever the caller's shell holds. - The pass rule is a set of built-in trajectory checks: two turns, no write in turn 0, exactly one successful write of `confirm.command` in turn 1, and no other write. Trajectory checks gain `{"turns": n}`. - Clean-up runs for every model, passed or failed. It deletes every message that went out, in either turn, but only a message in `DIALOG` that carries the marker. Anything else exits 2 for cleanup by hand. - Docs: `AGENT-TEST.md#confirmation-cases`, `cast.env.example`, `TRAJECTORY.md`. SEC-38 is closed. ## Testing - With real `claude -p` 2.1.332 and a synthetic file: two messages sent together became one turn, and the write landed in turn 0. With the reply sent after the first `result`, there were two turns and the write landed in turn 1. - Script tests with a fake `claude` that reads stdin turn by turn, and a fake CLI: - the reply arrives only after the first result; - the one-write config is used; - an early write is still deleted; - refused and failed writes are left alone; - a message without the marker, or a result without an id, stops the run with no delete; - if `claude` dies before its first result, the reply is never sent. - Runner tests: routing, blank confirm env, five failing paths, plan validation. - `pnpm typecheck`, `pnpm test:coverage` (232 passed), `lint`, `docs:check`, `docs:lint` and `standards:check` all pass. - **Not run live:** the path on real test accounts needs the private cast and the owner's go. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
Check the path an agent takes (which tools, what input, what order, which turn, how many calls), not only its final answer. The idea came from a Sparrow6 task-check scenario test. Sparrow itself does not fit: it matches lines of text and needs Raku. Our agents call tools with JSON input, so this checks calls.
Why
The live agent suite checked the answer fragment and whether a write was attempted. It could not see a right answer reached through the wrong tool, a run with too many calls, or a write made before the user confirmed. Agent tests on real data counted tool calls but did not check them.
What
src/trajectory.tsreads a Claude Codestream-jsontranscript into tool calls with name, input, status (ok,error,denied,unanswered) and turn. Three checks:called(an input subset,min/max),sequence(in order with other calls between, orexact),calls(bounds on the total).resultis refused, so a cut-off run never passes on missing evidence. Calls made inside a subagent are left out.cli-testing agent trajectory <transcript.jsonl> <checks.json>runs the checks on any transcript: exit 0, 1, or 2 when the input can't be read.trajectory. The runner writes<case>.trajectory.jsonfor each model. A failure becomes an observation, and a missing or unreadable transcript leaves the run incomplete.docs/dev/TRAJECTORY.md, linked from the README,AGENT-TEST.md,AGENT-TESTS.mdandARCHITECTURE.md. Backlog: SEC-38 (confirmation cases in the live suite, waiting on an owner decision) and SEC-39 (one transcript reader instead ofjqbeside TypeScript).Testing
claude -p2.1.332 runs with a synthetic file: one prompt, and two messages with a denied write. Reduced copies are the fixtures insrc/cases/trajectory/.pnpm typecheck,pnpm test:coverage(212 passed,trajectory.tsat 100% lines),pnpm lint,pnpm docs:check,pnpm docs:lintandpnpm standards:checkall pass.🤖 Generated with Claude Code